package roy.abc.study.WebServices.JavaWSUpAndRunning.ch01.ts;

import javax.xml.ws.Endpoint;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TimePublisherMT {
	private static Logger logger = LoggerFactory.getLogger(TimePublisherMT.class);
	private Endpoint endpoint;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TimePublisherMT timePublisherMT = new TimePublisherMT();
		timePublisherMT.createEndpoint();
		timePublisherMT.configureEndpoint();
		timePublisherMT.publish();
		
		try {
			Thread.sleep(1 * 60 * 1000);
		} catch (InterruptedException e) {
			logger.error(e.getMessage());
			e.printStackTrace();
		}
		logger.debug("Service exited.");
		System.exit(0);
	}
	
	private void createEndpoint(){
		endpoint = Endpoint.create(new TimeServerImpl());
	}
	
	private void configureEndpoint(){
		endpoint.setExecutor(new MyThreadPool());
	}
	
	private void publish() {
		int port = 8888;
		String url = "http://localhost:" + port + "/ts";
		endpoint.publish(url);
		logger.debug("Publishing TimeServer on port " + port);
	}
}
